//分类模块
import { topCategory } from "@/api/constants" //防止白屏
import { findAllCategory } from "@/api/category"
export default {
    namespaced: true,
    state: () => {
        return {
            list: topCategory.map(item => ({ name: item }))
        }
    },
    mutations: {
        setList(state, value) {
            state.list = value
            // console.log("store/category:", state.list)
        },
        Show(state, value) {
            let currentCategory = state.list.find(item => item.id === value.id)
            currentCategory.open = true
        },
        Hide(state, value) {
            let currentCategory = state.list.find(item => item.id === value.id)
            currentCategory.open = false
        }
    },
    actions: {
        async getList(ctx) {
            let res = await findAllCategory()
            res.result.forEach(item => { item.open = false })
            ctx.commit('setList', res.result)
        }
    }
}